﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ELab.Controls
{
    public partial class ScreenViewer : UserControl
    {
        public ScreenViewer()
        {
            InitializeComponent();
            PictureBox.MouseClick += PictureBox_MouseClick;
            PictureBox.MouseDoubleClick += PictureBox_MouseDoubleClick;
            PictureBox.MouseDown += PictureBox_MouseDown;
            PictureBox.MouseUp += PictureBox_MouseUp;
            PictureBox.MouseEnter += PictureBox_MouseEnter;
            PictureBox.MouseHover += PictureBox_MouseHover;
            PictureBox.MouseMove += PictureBox_MouseMove;
            PictureBox.MouseWheel += PictureBox_MouseWheel;
            PictureBox.Move += PictureBox_Move;
            PictureBox.Click += PictureBox_Click;
            PictureBox.DoubleClick += PictureBox_DoubleClick;
        }

        public Image Image
        {
            get { return PictureBox.Image; }
            set { SetImage(value); }
        }


        public string ServerRemode { get; set; }
        public string UserRemode { get; set; }
        public string PasswordRemode { get; set; }

        public void Connect(string server, string user, string pass)
        {
            this.ServerRemode = server;
            this.UserRemode = user;
            this.PasswordRemode = pass;
            SetImageBoxVisible(false);
        }

        #region Private method
        /// <summary>
        /// 
        /// </summary>
        /// <param name="image"></param>
        private void SetImage(Image image)
        {
            if (PictureBox.InvokeRequired)
            {
                BeginInvoke((MethodInvoker)delegate() { SetImage(image); });
            }
            else
            {
                PictureBox.Image = image;
                PictureBox.Visible = true;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="image"></param>
        private void SetImageBoxVisible(bool visibled)
        {
            if (PictureBox.InvokeRequired)
            {
                BeginInvoke((MethodInvoker)delegate() { SetImageBoxVisible(visibled); });
            }
            else
            {
                PictureBox.Visible = visibled;
            }
        }
        #endregion

        #region Overide method
        private void PictureBox_MouseClick(object sender, MouseEventArgs e)
        {
            OnMouseClick(e);
        }

        private void PictureBox_DoubleClick(object sender, EventArgs e)
        {
            OnDoubleClick(e);
        }

        private void PictureBox_Click(object sender, EventArgs e)
        {
            OnClick(e);
        }

        private void PictureBox_MouseUp(object sender, MouseEventArgs e)
        {
            OnMouseUp(e);
        }

        private void PictureBox_Move(object sender, EventArgs e)
        {
            OnMove(e);
        }

        private void PictureBox_MouseWheel(object sender, MouseEventArgs e)
        {
            OnMouseWheel(e);
        }

        private void PictureBox_MouseMove(object sender, MouseEventArgs e)
        {
            OnMouseMove(e);
        }

        private void PictureBox_MouseHover(object sender, EventArgs e)
        {
            OnMouseHover(e);
        }

        private void PictureBox_MouseEnter(object sender, EventArgs e)
        {
            OnMouseEnter(e);
        }

        private void PictureBox_MouseDown(object sender, MouseEventArgs e)
        {
            OnMouseDown(e);
        }

        private void PictureBox_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            OnMouseDoubleClick(e);
        }
        #endregion
    }
}
